#include <iostream>
#include <cstring>
using namespace std;
#define maxn 105
const int INF = 1<<30;

int n;
int w[2*maxn];
int s[2*maxn];
int dp1[2*maxn][2*maxn], dp2[2*maxn][2*maxn];

int dfs1(int l, int r){
	if(dp1[l][r]>=0) return dp1[l][r];
	if(l==r) return 0;
	int ret = 0;
	for(int i=l; i<r; i++){
		ret = max(ret, dfs1(l, i)+dfs1(i+1, r)+s[r]-s[l-1]);
	}
	return dp1[l][r] = ret;
}

int dfs2(int l, int r){
	if(dp2[l][r]>=0) return dp2[l][r];
	if(l==r) return 0;
	int ret = INF;
	for(int i=l; i<r; i++){
		ret = min(ret, dfs2(l, i)+dfs2(i+1, r)+s[r]-s[l-1]);
	}
	return dp2[l][r] = ret;
}

int main(){
	memset(dp1, -1, sizeof(dp1));
	memset(dp2, -1, sizeof(dp2));
	cin>>n;
	for(int i=1; i<=n; i++){
		cin>>w[i];
		w[i+n]=w[i];
	}
	for(int i=1; i<=2*n; i++){
		s[i]=s[i-1]+w[i];
	}
	
	int maxans=0, minans=INF;
	for(int l=1; l<=n; l++){
		int r = l+n-1;
		maxans = max(maxans, dfs1(l, r));
		minans = min(minans, dfs2(l, r));
	}
	cout<<minans<<endl<<maxans<<endl;
	
	return 0;
}